package vboot.core.module.sys.portal.main;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vboot.core.common.api.R;
import vboot.core.common.dao.Sqler;

@RestController
@RequestMapping("sys/portal/main")
public class SysPortalMainApi {

    @GetMapping
    public R get(String name) {
        Sqler sqler = new Sqler("sys_portal_main");
        sqler.addLike("t.name" , name);
        sqler.addOrder("t.ornum");
        return R.ok(service.findPageData(sqler));
    }

    @GetMapping("list")
    public R getList() {
        return R.ok(service.findAll());
    }


    @GetMapping("one/{id}")
    public R getOne(@PathVariable String id) {
        SysPortalMain main = service.findOne(id);
        return R.ok(main);
    }

    @PostMapping
    public R post(@RequestBody SysPortalMain main) {
        return R.ok(service.insert(main));
    }

    @PutMapping
    public R put(@RequestBody SysPortalMain main) {
        return R.ok(service.update(main));
    }

    @DeleteMapping("{ids}")
    public R delete(@PathVariable String[] ids) {
        return R.ok(service.delete(ids));
    }

    @Autowired
    private SysPortalMainService service;

}
